Method and Device for Setting Up Wireless Network Connection

ABSTRACT

The present invention provides a method and device for setting up a wireless network connection. The second device sets up a connection with the wireless network according to the network configuration information. With the present invention, user participation when a terminal is connected to the wireless network is reduced, and efficiency in setting up a wireless network connection is improved.

CROSS-REFERENCE TO RELATED APPLICATION

This application is a continuation of International Application No.PCT/CN2012/080230, filed on Aug. 16, 2012, which is hereby incorporatedby reference in its entirety.

STATEMENT REGARDING FEDERALLY SPONSORED RESEARCH OR DEVELOPMENT

Not applicable.

REFERENCE TO A MICROFICHE APPENDIX

Not applicable.

TECHNICAL FIELD

The present invention relates to communication technologies, and inparticular, to a method and device for setting up a wireless networkconnection.

BACKGROUND

Due to advantages such as rapid deployment, convenience for use, andhigh transmission rate, a wireless local area network (e.g., a WirelessFidelity (WiFi) network) develops rapidly and is widely applied invarious fields. At present, many notebook computers, mobile phones andso on support a WiFi technology, and access points (AP) of a WiFinetwork are widely available at places such as hotels, coffee shops, andhospitals.

When a connection is set up in the WiFi network, network configurationinformation, for example, a key, which is needed for setting up theconnection with the WiFi network, needs to be configured on a terminalfirst, so that the terminal can set up the connection with the AP andaccess the WiFi network. In the prior art, the network configurationinformation is usually entered manually by a user. For example, in arestaurant such as McDonald's or a coffee shop, the user needs to get apiece of password paper at a service counter and enter a password(namely, network configuration information) on the password paper onto aterminal of the user, so that the user can access the WiFi network inthe restaurant; or, when an enterprise holds an internal meeting in ameeting room, in order to prevent another person outside the meetingroom from accessing, participants in the meeting room also need to entera password (namely network configuration information) manually, so thatthe participants can access the WiFi network in the meeting room afterauthentication.

To simplify a process of setting up the connection with the WiFinetwork, the WiFi alliance formulates a wireless network security setup(e.g., a WiFi protected setup (WPS)) method, and the automaticconfiguration of part of information needed by a network, for example, aservice set identifier (SSID) may be implemented through WPS and thesecurity connection of the network is implemented. However, at thebeginning of the WPS process, network configuration information alsoneeds to be configured on the terminal, so that the terminal sets up theconnection with the AP according to the network configurationinformation and subsequent transmission of information such as the SSIDof the WPS can be executed. In addition, the network configurationinformation on the terminal is also configured manually by a user, forexample, the user needs to search the AP for a personal identificationnumber (PIN) located on the label of the AP, and then enter the PIN ontothe terminal manually.

To sum up, currently, when the connection is set up in the WiFi network,the operation of configuring the network configuration information onthe terminal is complex and mostly requires manual participation of theuser, thereby causing low efficiency in setting up a wireless networkconnection.

SUMMARY

Embodiments of the present invention provide a method and device forsetting up a wireless network connection to reduce user participationwhen a terminal is connected to an AP and improve efficiency in settingup a wireless network connection.

A first aspect of the embodiment of the present invention provides amethod for setting up a wireless network connection, where the methodincludes: sending, by a first device, a probe message to a second deviceby using a first transmit power, and receiving a first response messagereturned by the second device, where the first response message carriesa first receive power when the second device receives the probe message;or, sending, by the first device, a probe message to the second device,where the probe message is used to instruct the second device to send asecond response message by using a second transmit power, and receiving,by the first device, the second response message, and obtaining, throughdetection, a second receive power when receiving the second responsemessage; or, sending, by the first device, a probe message to a seconddevice by using a first transmit power, where the probe message is usedto instruct the second device to send a third response message by usinga second transmit power, receiving, by the first device, the thirdresponse message, where the third response message carries a firstreceive power when the second device receives the probe message, andobtaining, by the first device and through detection, a second receivepower when receiving the third response message; obtaining, by the firstdevice and according to the first transmit power and the first receivepower or according to the second transmit power and the second receivepower, a path loss between the first device and the second device; andwhen determining, according to the path loss, that a distance betweenthe first device and the second device is within a preset distancerange, sending, by the first device, network configuration informationneeded for accessing a wireless network to the second device, so thatthe second device sets up a connection with the wireless networkaccording to the network configuration information.

In one possible implementation manner, the path loss obtained by thefirst device according to the first transmit power and the first receivepower is a first path loss; the path loss obtained by the first deviceaccording to the second transmit power and the second receive power is asecond path loss; and after the first device determines, according tothe path loss, that the distance between the first device and the seconddevice is within the preset distance range and before the first devicesends the network configuration information needed for accessing thewireless network to the second device, the method further includes:comparing, by the first device, the second path loss with the first pathloss, and if a loss variation value between the two is within a presetloss variation value range, identifying a terminal as a real device.

In another possible implementation manner, there are multiple pathlosses obtained by the first device; and after the first devicedetermines, according to the path loss, that the distance between thefirst device and the second device is within the preset distance rangeand before the first device sends the network configuration informationneeded for accessing the wireless network to the second device, themethod further includes: calculating, by the first device, a floatingvariation value of the multiple path losses, and if the floatingvariation value is within a preset floating variation value range,identifying a terminal as a real device.

In still another possible implementation manner, before the first devicesends the probe message to the second device, the method furtherincludes: obtaining, by the first device, a key from the second deviceby using a key exchange algorithm to encrypt, by using the key, theprobe message sent to the second device and decrypt, by using the key,the response message received from the second device, where the responsemessage is the first response message, the second response message orthe third response message.

Another aspect of the embodiments of the present invention provides amethod for setting up a wireless network connection, where the methodincludes: receiving, by a second device, a probe message that is sent bya first device by using a first transmit power, and returning a firstresponse message to the first device, where the first response messagecarries a first receive power when the second device receives the probemessage; or, receiving, by the second device, a probe message sent bythe first device, where the probe message is used to instruct the seconddevice to send a second response message by using a second transmitpower, and sending, by the second device, the second response message tothe first device, so that the first device obtains, through detection, asecond receive power when receiving the second response message; or,receiving, by the second device, a probe message that is sent by thefirst device by using a first transmit power, where the probe message isused to instruct the second device to send a third response message byusing a second transmit power, sending, by the second device, the thirdresponse message to the first device, where the third response messagecarries a first receive power when the second device receives the probemessage, so that the first device obtains, through detection, a secondreceive power when receiving the third response message; receiving, bythe second device, network configuration information which is needed foraccessing a wireless network and sent by the first device, where thenetwork configuration information is sent by the first device when thefirst device determines, according to the first transmit power and thefirst receive power or according to the second transmit power and thesecond receive power, that a distance between the first device and thesecond device is within a preset distance range; and setting up, by thesecond device, a connection with the wireless network according to thenetwork configuration information.

In one possible implementation manner, before the second device receivesthe probe message sent by the first device, the method further includes:obtaining, by the second device, a key from the first device by using akey exchange algorithm to encrypt, by using the key, a response messagesent to the first device and decrypt, by using the key, the probemessage received from the first device, where the response message isthe first response message, the second response message or the thirdresponse message.

Still another aspect of the embodiments of the present inventionprovides a first device, including: a message transmitting unitconfigured to: send a probe message to a second device by using a firsttransmit power, and receive a first response message returned by thesecond device, where the first response message carries a first receivepower when the second device receives the probe message; or, send aprobe message to the second device, where the probe message is used toinstruct the second device to send a second response message by using asecond transmit power, receive the second response message, and obtain,through detection, a second receive power when receiving the secondresponse message; or, send a probe message to a second device by using afirst transmit power, where the probe message is used to instruct thesecond device to send a third response message by using a secondtransmit power; receive the third response message, where the thirdresponse message carries a first receive power when the second devicereceives the probe message; and obtain, through detection, a secondreceive power when receiving the third response message; a distancedetermining unit configured to: obtain, according to the first transmitpower and the first receive power or according to the second transmitpower and the second receive power, a path loss between the first deviceand the second device; and determine, according to the path loss, that adistance between the first device and the second device is within apreset distance range; and an information sending unit configured to,when the distance determining unit determines that the distance betweenthe first device and the second device is within the preset distancerange, send network configuration information to the second device, sothat the second device sets up, according to the network configurationinformation, a connection with the wireless network.

In one possible implementation manner, the path loss obtained by thedistance determining unit according to the first transmit power and thefirst receive power is a first path loss, and the path loss obtainedaccording to the second transmit power and the second receive power is asecond path loss.

The first device further includes a device identifying unit configuredto: compare the second path loss with the first path loss, and if a lossvariation value between the two is within a preset loss variation valuerange, identify a terminal as a real device, and instruct theinformation sending unit to send the network configuration informationto the second device.

In another possible implementation manner, there are multiple pathlosses obtained by the distance determining unit; and the deviceidentifying unit is further configured to: calculate a floatingvariation value of the multiple path losses, and if the floatingvariation value is within a preset floating variation value range,identify a terminal as a real device, and instruct the informationsending unit to send the network configuration information to the seconddevice.

In another possible implementation manner, a key exchanging unit isconfigured to, before the probe message is sent to the second device,obtain, by the first device, a key from the second device by using a keyexchange algorithm to encrypt, by using the key, the probe message sentto the second device and decrypt, by using the key, a response messagereceived from the second device, where the response message is the firstresponse message, the second response message or the third responsemessage.

Still another aspect of the embodiments of the present inventionprovides a second device, including: a message transmitting unitconfigured to: receive a probe message that is sent by a first device byusing a first transmit power, and return a first response message to thefirst device, where the first response message carries a first receivepower when the second device receives the probe message; or, receive aprobe message sent by the first device, where the probe message is usedto instruct the second device to send a second response message by usinga second transmit power, and send the second response message to thefirst device, so that the first device obtains, through detection, asecond receive power when receiving the second response message; or,receive a probe message that is sent by the first device by using afirst transmit power, where the probe message is used to instruct thesecond device to send a third response message by using a secondtransmit power, and send the third response message to the first device,where the third response message carries a first receive power when thesecond device receives the probe message, so that the first deviceobtains, through detection, a second receive power when receiving thethird response message; an information receiving unit configured toreceive network configuration information which is needed for accessinga wireless network and sent by the first device, where the networkconfiguration information is sent by the first device when the firstdevice determines, according to the first transmit power and the firstreceive power or according to the second transmit power and the secondreceive power, that a distance between the first device and the seconddevice is within a preset distance range; and a connection setup unitconfigured to set up a connection with the wireless network according tothe network configuration information.

In one possible implementation manner, the second device furtherincludes a key exchanging unit configured to, before the probe messagesent by the first device is received, obtain a key from the first deviceby using a key exchange algorithm to encrypt, by using the key, aresponse message sent to the first device and decrypt, by using the key,the probe message received from the first device, where the responsemessage is the first response message, the second response message orthe third response message.

Technical effects of the method and device for wireless network setupprovided in the embodiments of the present invention are: When the firstdevice determines, according to the path loss between the first deviceand the second device, that the distance between the second device andthe first device is within the preset distance range, the first devicesends the network configuration information to the second device. Inthis manner, a user only needs to make the first device and the seconddevice close to each other, so that the first device may automaticallyexecute the foregoing calculation and determination, and automaticallysend the network configuration information to the second device.Compared with manners in the prior art, such as a manner in which theuser manually searches for and enters a PIN, an operation process thatthe user participates in is greatly simplified, and compared with amanual configuration process, an automatic configuration process alsoimproves efficiency of wireless network setup.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a schematic flowchart of an embodiment of a method for settingup a wireless network connection according to the present invention;

FIG. 2 is a schematic flowchart of another embodiment of a method forsetting up a wireless network connection according to the presentinvention;

FIG. 3 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention;

FIG. 4 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention;

FIG. 5 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention;

FIG. 6 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention;

FIG. 7 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention;

FIG. 8 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention;

FIG. 9 is a schematic structural diagram of an embodiment of a firstdevice according to the present invention;

FIG. 10 is a schematic structural diagram of another embodiment of afirst device according to the present invention;

FIG. 11 is a schematic structural diagram of an embodiment of a seconddevice according to the present invention;

FIG. 12 is a schematic structural diagram of still another embodiment ofa first device according to the present invention; and

FIG. 13 is a schematic structural diagram of another embodiment of asecond device according to the present invention.

DETAILED DESCRIPTION

The following concept in embodiments of the present invention isdescribed first.

In the embodiments of the present invention, a first device may be adevice having functions of detecting, calculating, and sending, forexample, a mobile terminal having the foregoing functions. In each ofthe following embodiments of the present invention, the first device isreferred to as an AP mate; the AP mate pre-stores network configurationinformation, and automatically sends the network configurationinformation to a second device.

The second device refers to various terminals that intend to access awireless network, for example, a mobile phone and a notebook computer;and in each embodiment of the present invention, processes executed bythe second device are described by taking a terminal as an example.

The wireless network is not limited to a WiFi network, for example, itmay also be applicable to wireless networks such as WorldwideInteroperability for Microwave Access (WiMax), Zigbee, 3rd Generation ofMobile Telecommunications Technology (3G), and Global System for MobileCommunications (GSM).

In addition, a probe message in the embodiments of the present inventionis a message that is sent by the first device to the second device andis used to probe a path loss between the first device and the seconddevice. In specific implementation, the probe message may be a messagesent independently, that is, the first device specially sends the probemessage to the second device, or the probe message may be an existingmessage between the first device and the second device, where themessage also has a function required by the embodiments and is alsoreferred to as a probe message. For example, if an instruction parameterused to instruct the second device to return a response message by usinga certain transmit power is added to an existing message, the existingmessage has a function of the probe message in the embodiments of thepresent invention, and may also be referred to as a probe message.

Embodiment 1

FIG. 1 is a schematic flowchart of an embodiment of a method for settingup a wireless network connection according to the present invention. Themethod in this embodiment is executed by an AP mate. As shown in FIG. 1,the method may include:

101. Transmit a probe message between the AP mate and a terminal, andobtain a transmit power and a receive power when the probe message isunidirectionally transmitted between the AP mate and the terminal.

The unidirectional transmission refers to that, for example, the local,namely, the AP mate, sends the probe message and the terminal receivesthe probe message, where the message is transmitted from the AP mate tothe terminal; or the terminal sends the probe message and the AP matereceives the probe message, where the message is transmitted from theterminal to the AP mate.

Accordingly, in the unidirectional transmission, if the message istransmitted from the AP mate to the terminal, a power when the AP matesends the probe message is the transmit power, while a power when theterminal receives the probe message is the receive power. If the messageis transmitted from the terminal to the AP mate, a power when theterminal sends the probe message is the transmit power, while a powerwhen the AP mate receives the probe message is the receive power.

For example, the AP mate sends a probe message to the terminal by usinga first transmit power, and receives a first response message returnedby the terminal, where the first response message carries a firstreceive power when the terminal receives the probe message.

For another example, the AP mate sends a probe message to the terminal,where the probe message is used to instruct the terminal to send asecond response message by using a second transmit power, and the APmate receives the second response message and obtains, throughdetection, a second receive power when receiving the second responsemessage.

For still another example, the AP mate sends a probe message to theterminal by using a first transmit power, where the probe message isused to instruct the terminal to send a third response message by usinga second transmit power, the AP mate receives the third responsemessage, where the third response message carries a first receive powerwhen the terminal receives the probe message, and the AP mate obtains,through detection, a second receive power when receiving the thirdresponse message.

The foregoing third manner (that is, the manner in the still anotherexample) is different from the previous two manners in that, in theprevious two manners, two powers are obtained by transmitting twomessages. For example, in the first manner, two powers, namely, thefirst transmit power and the first receive power, are obtained bytransmitting two messages, namely, the probe message and the firstresponse message. While in the third manner, four powers are obtained bytransmitting two messages, and efficiency is higher. For example, fourpowers, namely, the first transmit power, the first receive power, thesecond transmit power, and the second receive power, are obtained bytransmitting two messages, namely, the probe message and the thirdresponse message.

It should be noted that, several feasible manners are listed in theforegoing, which only intends to express that these manners may beadopted when a first device obtains a power (such as the first transmitpower and the first receive power), and each of the manners can be usedto obtain a power parameter value. However, in this embodiment, it isnot limited that only one of the manners can be executed in the methodin this embodiment. It can also be seen from subsequent embodiments thatin specific implementation, the first device may execute one of theforegoing three manners or any combination of the foregoing threemanners, or execute a certain manner multiple times, and so on, whichdepends on the actual execution need of the first device. For example,when the first device needs to determine whether a second device is areal device, the first device may need to execute a combination of theforegoing manners or execute a certain manner multiple times to obtain arelated parameter.

In addition, it should also be noted that, a power parameter in thisembodiment, for example, the first transmit power, the first receivepower, may also be converted into another measuring unit in specificimplementation. The power in this embodiment involves the followingcase. For example, a power value may be equivalently converted into asignal strength value, Signal strength=10*log₁₀(power value), where aunit of signal strength is decibels relative to one milliwatt (dBm), anda unit of the power value is milliwatt (mW).

102. According to the first transmit power and the first receiver poweror according to the second transmit power and the second receive power,obtain a path loss between the AP mate and the terminal duringtransmission.

The path loss may be calculated according to an existing path lossformula, that is, “path loss=32.5+20*log(f)+log(D),” where path loss isin the unit of dB, where f is frequency in the unit of gigahertz (GHz),and where D is distance in the unit of meter (m).

It can be seen from the foregoing path loss formula that the path lossis related to a distance, different distances bring about differentlosses. In general, the farther the distance is, the higher the pathloss is.

The AP mate may obtain the path loss according to the first transmitpower and the first receive power, and may also obtain, throughcalculation, the path loss according to the second transmit power andthe second receive power. These two manners are optional manners. Inspecific implementation, the AP mate may select any manner to calculatethe path loss, or execute both manners to obtain multiple path losses.

103. When determining, according to the path loss, that a distancebetween the terminal and the AP mate is within a preset distance range,send network configuration information to the terminal.

In this embodiment, it is set that the AP mate determines the distancebetween the terminal and the AP mate according to the path loss, and ifthe distance is within the preset distance range, the AP mate sends thenetwork configuration information to the terminal. That is, the distanceis used as a condition for triggering sending of the networkconfiguration information to the terminal by the AP mate. In specificimplementation, when a user intends a certain terminal to execute a WPSconnection with the AP mate, the user may make the terminal close to theAP mate or make the AP mate close to the terminal, and then the AP mateautomatically executes the foregoing steps. The AP mate calculates apath loss, and determines a distance between the terminal and the APmate according to the path loss; if a preset distance range is met, theAP mate automatically sends network configuration information to theterminal.

In this manner, the user only needs to make the AP mate and the terminalclose to each other. Compared with manners in the prior art, such as amanner in which a user manually searches for and enters a PIN, theoperation is simpler for the user, and user participation is greatlyreduced; in addition, a label bearing the PIN does not need to be set onthe AP, which also reduces a device cost.

There may be multiple manners for determining the distance between theterminal and the AP mate according to the path loss. For example,assuming that the preset distance range is 1 m-1.5 m, the AP mate mayobtain, through calculation, a distance D according to the path loss andthe foregoing path loss formula, and determines whether D is within 1m-1.5 m; or the AP mate converts the preset distance range 1 m-1.5 minto a path loss range in advance according to the preset distance range1 m-1.5 m and the foregoing path loss formula. For example, a path losscorresponding to 1 m is q1 and a path loss corresponding to 1.5 m is q2,that is, a preset path loss range is q1-q2, and then the AP mate onlyneeds to determine whether the obtained path loss is within the presetpath loss range; if the obtained path loss is within the range, itindicates that the distance between the terminal and the AP mate iswithin the preset distance range.

It should be noted that the preset distance range includes a pointvalue, for example, it is a distance value rather than a distance range.For example, if the preset distance range is 1 m, the AP mate only needsto determine whether a distance corresponding to the path loss is 1 m.In addition, the preset distance range may be set by the userindependently. In specific implementation, for example, a userinteractive interface may be set on the AP mate, and the user mayproperly adjust the preset distance range or the preset path loss rangeat any time through the interface.

The network configuration information, for example, may be a PIN codeand a key of the AP. If the network configuration information is a key,a length of the key in this embodiment may be set to any value to ensurenetwork security after configuration. After obtaining the networkconfiguration information, the terminal sets up a wireless networkconnection with the AP according to the network configurationinformation. The setting up the wireless network connection is, forexample: After setting up a connection with the AP, the terminalexecutes a wireless network security setup WPS procedure between theterminal and the AP, for example, performing authentication and WiFiconfiguration information transmission with the AP, where the WPSprocedure is an existing processing procedure, and details are notfurther described.

Embodiment 2

FIG. 2 is a schematic flowchart of another embodiment of a method forsetting up a wireless network connection according to the presentinvention. The method in this embodiment is executed by a terminal. Asshown in FIG. 2, the method may include:

201. Transmit a probe message between the terminal and an AP mate, andreport, to the AP mate, a receive power when receiving the probemessage, or send a response message by using a transmit power instructedby the AP mate.

When the probe message is transmitted from the AP mate to the terminal,the terminal reports, to the AP mate, the receive power when receivingthe probe message, and the AP mate itself learns its transmit power; orwhen the probe message is transmitted from the terminal to the AP mate,the terminal may report the transmit power of the message to the APmate. Because the transmit power is a power with which the terminalsends the probe message as instructed by the AP mate, the AP mate mayalso learn the transmit power even if the terminal does not report it.The AP mate itself also obtains the receive power when receiving theprobe message. Through the foregoing step, the AP mate obtains thetransmit power and receive power of the probe message in unidirectionaltransmission.

For a specific execution manner, reference may be made to thedescription of 101 in Embodiment 1, and details are not furtherdescribed.

202. Receive network configuration information sent by the AP mate.

The network configuration information may be, for example, a PIN codeand a key of the AP. The network configuration information is sent bythe AP mate when the AP mate calculates, according to the foregoingtransmit power and receive power, a path loss occurring in thetransmission of the probe message, and determines, according to the pathloss, that a distance between the terminal and the AP mate is within apreset range. That is, through step 201 and step 202, the AP mate mayautomatically determine the distance between the terminal and the APmate, and automatically send the network configuration information tothe terminal when the distance is within the preset distance range. Inthis manner, a user only needs to make the AP mate and the terminalclose to each other, which greatly simplifies a user's operation.

203. Set up a connection with a wireless network according to thenetwork configuration information.

Interaction processes between the AP mate and the terminal are describedin detail in the following Embodiment 3 to Embodiment 7, and severalfeasible implementation manners are illustrated. A same process involvedin the embodiments is described in detail in one embodiment only, and isbriefly described in other embodiments.

First, several scenarios in which the method for setting up a wirelessnetwork connection in each embodiment of the present invention can beapplied are illustrated. For example, when an internal meeting is heldin a meeting room, an AP mate may be set in the meeting room, thefollowing method processes are executed between the AP mate and aterminal of each participant in the meeting room, the terminal isconfigured automatically, and participants do not need to obtain apassword any longer; or, in restaurants such as McDonald's and KentuckyFried Chicken (KFC), an AP mate may also be set, the AP mate and aterminal of a customer automatically execute the following methodprocesses, the terminal is configured automatically, and the customerdoes not need to get a piece of password paper at a service counter; or,in WPS configuration, a user does not need to enter networkconfiguration information, for example, a PIN code, manually into aterminal any longer, but may make the terminal and an AP mate close toeach other, and the AP mate and the terminal execute the followingmethod processes. The AP mate can automatically identify a user within acertain range, for example, a meeting room range, a store range, or aclose range preset during WPS, and automatically send networkconfiguration information to the terminal, and the terminal isautomatically connected to a network according to the information, whichomits complex processes such as entering a password by the user.

Embodiment 3

FIG. 3 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention. In this embodiment, a power when an AP mate sends aprobe message is a first transmit power, and a power when a terminalreceives the probe message is a first receive power. As shown in FIG. 3,the method may include:

301. The AP mate and the terminal obtain a key by using a key exchangealgorithm.

Before a probe message is transmitted, the AP mate and the terminal mayobtain the key by using the key exchange algorithm. An interactionprocess in this step is mainly that the AP mate and the terminalexchanges some parameters needed to generate a key; and then the AP mateand the terminal each generate, according to the exchanged parameters, akey by using the key exchange algorithm. In subsequent processes oftransmitting the probe message, the key is used to encrypt the probemessage for transmission or to decrypt a response message returned bythe terminal, to better ensure security of message transmission.

The foregoing key exchange algorithm may be a commonly-used algorithm,for example, Diffie-Hellman (D-H) key exchange algorithm, RSA algorithmfor public-key encryption and the security. In addition, to triggerexecution of the key exchange process between the AP mate and theterminal, optionally, a trigger button may be set on each of the AP mateand the terminal. After a user makes the AP mate and the terminal closeto each other, this trigger button is pressed, and the AP mate and theterminal execute this step.

302. The AP mate sends a probe message to the terminal by using atransmit power P.

The transmit power P may be referred to as a first transmit power, maybe preset in the AP mate and may also be generated by the AP materandomly. However, the transmit power P is learned by the AP mate only.In addition, when sending the probe message, the AP mate may instructthe terminal to report a receive power when the terminal receives theprobe message, for example, the AP mate may carry an instructionidentifier in the probe message, so that the terminal reports thereceive power according to the instruction identifier.

303. The terminal reports, to the AP mate, a receive power PA whenreceiving the probe message.

The terminal may report, according to the instruction identifier carriedin the probe message sent by the AP mate and to the AP mate, theattenuated receive power when the terminal receives the probe message.For example, the terminal returns a first response message to the APmate, where the first response message carries a first receive powerwhen the terminal receives the probe message.

304. The AP mate calculates, according to the transmit power and thereceive power for transmission of the probe message, a path loss in thetransmission of the probe message from the AP mate to the terminal.

The transmit power is the first transmit power when the AP mate sendsthe probe message in 302, and the receive power is the first receivepower which is reported by the terminal to the AP mate in 303. Powerattenuation always occurs in message transmission. Generally, the longera distance is, the more the power attenuation is. Therefore, thetransmit power P (e.g., the first transmit power) is greater than thereceive power PA (e.g., the first receive power).

For example, the AP mate calculates the path loss as “P-PA,” which isthe path loss occurring when the probe message is transmitted from theAP mate to the terminal. It should be noted that the path loss is notnecessarily a difference between the transmit power and the receivepower so long as it can indicate variation between the transmit powerand the receive power. For example, the path loss may also be a ratiobetween the transmit power and the receive power or may be indicated byother mathematic methods that can indicate the variation. For example,First path loss=log₁₀(first transmit power)−log₁₀(first receive power).

305. The AP mate determines, according to the path loss, whether adistance between the terminal and the AP mate is within a presetdistance range.

After obtaining the path loss P-PA through the calculation, the AP matedetermines the distance between the terminal and the AP mate accordingto the path loss. As described above, the AP mate may performdetermination according to the preset distance range or a preset losspath range.

For example, the value of the path loss P-PA is a dB. The AP mate mayobtain, through the calculation, a distance D1 between the terminal andthe AP mate according to a path loss formula “pathloss=32.5+20*log(f)+log(D),” and in combination with a power f (GHz) ofthe probe message. Assuming that the D1 is 1 m and the preset distancerange set in the AP mate is 0.9 m-1.2 m, the AP mate may determine that1 m is within the range of 0.9 m-1.2 m.

For another example, the value of the path loss P-PA is a dB, and the APmate obtains, through conversion in advance, a preset loss rangeaccording to a preset distance range of 0.9 m-1.2 m and the foregoingpath loss formula. Specifically, when the distance is 0.9 m, a path losscalculated according to the formula is A1; when the distance is 1.2 m, apath loss calculated according to the formula is A2. In this case, thepreset loss range is A1-A2. The AP mate determines whether the value aof the P-PA is within the range of A1-A2; if yes, it indicates that theterminal is also within the preset distance range.

The foregoing preset distance range or the preset loss range may bevariable. For example, a user interactive interface may be set on the APmate, and the user may properly adjust the preset distance range or thepreset path loss range at any time through the interface.

In this step, if a determination result of the AP mate is that theterminal is within the preset distance range, continue to execute 306;otherwise, if a determination result of the AP mate is that the terminalis not within the preset distance range, the process ends, and stopexecuting 306.

306. The AP mate sends network configuration information to theterminal.

In this embodiment, the AP mate determines, according to the distancebetween the AP mate and the terminal, whether to send the networkconfiguration information to the terminal. The user only needs to make aterminal, which intends to access a WiFi network, close to the AP mate,the AP mate automatically executes the foregoing processes ofcalculating and determining the distance between the AP mate and theterminal, and automatically sends network configuration information tothe terminal when the terminal is within the preset distance range. Forthe user, this manner greatly simplifies a user's operation processesbecause these processes are executed by the AP mate automatically.

307. The terminal sets up a network connection with the AP according tothe network configuration information.

For example, the setting up the network connection with the AP may beexecuting a WPS procedure with the AP, where the WPS procedure refersto, for example, performing authentication and WiFi configurationinformation transmission with the AP, and automatically configuringinformation such as an SSID and a network key. In this embodiment, theprocess in step 307 and the interaction processes between the AP mateand the terminal in the foregoing step 301 to step 306 are collectivelyreferred to as WPS implementation process. In addition, the AP may alsoexecute functions of a register, that is, perform functions such assetting up a network, and adding/deleting a device, to simplifyinteraction processes between devices and a WPS configuration process.

In addition, which message specifically carries information such as thetransmit power or the receive power is not limited in this embodiment solong as the information can be reported and the AP mate can obtain it.

Embodiment 4

FIG. 4 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention. In this embodiment, an AP mate instructs a terminalto return a response message by using a second transmit power, and apower when the AP mate receives the response message is a second receivepower. As shown in FIG. 4, the method may include:

401. The AP mate and the terminal obtain a key by using a key exchangealgorithm.

402. The AP mate sends a probe message to the terminal, where the probemessage is used to instruct the terminal to send a response message byusing a transmit power P1.

In this embodiment, the AP mate instructs the terminal to send a probemessage by using the transmit power P1, where the transmit power P1 maybe referred to as a second transmit power and may be carried by the APmate in the probe message to inform the terminal.

403. The terminal returns a response message to the AP mate by using thetransmit power P1.

The response message returned by the terminal may be referred to as asecond response message. The terminal may and may not carry the transmitpower P1 in the response message.

404. The AP mate obtains a receive power P1A when the AP mate receivesthe response message.

When receiving the response message sent by the terminal, the AP mateitself may obtain the receive power P1A when receiving the message,where the receive power P1A may be referred to as a second receivepower.

In addition, the AP mate may set that the terminal may not be allowed toaccess a wireless network if the terminal does not return a responsemessage. In specific implementation, the AP mate may set a timer, and ifa response message returned by the terminal is not received after thetimer expires, the AP mate may determine that the terminal is notallowed to access the wireless network.

405. The AP mate calculates, according to the obtained transmit powerand receive power, a path loss when the probe message is transmittedfrom the terminal to the AP mate.

The transmit power is the power P1 when the terminal sends the probemessage in 403; the receive power is the power P1A when the AP matereceives the probe message in 404. Because power attenuation alwaysoccurs in message transmission, the transmit power P1 is greater thanthe receive power P1A.

The AP mate calculates the path loss as “P1-P1A,” which is the path lossproduced when the probe message is transmitted from the terminal to theAP mate.

406. The AP mate determines, according to the path loss, whether adistance between the terminal and the AP mate is within a presetdistance range.

After obtaining the path loss P1-P1A through the calculation, the APmate determines the distance between the terminal and the AP mateaccording to the path loss. As described above, the AP mate may performdetermination according to the preset distance range or a preset lossrange. The method is the same as that in Embodiment 3, and is notfurther described.

If a determination result of the AP mate is that the terminal is withinthe preset distance range, continue to execute 407; otherwise, theprocess ends.

407. The AP mate sends network configuration information to theterminal.

408. The terminal sets up a network connection with the AP according tothe network configuration information.

In the foregoing Embodiment 3 and Embodiment 4 of the present invention,the AP mate implements automatic determination of the distance of theterminal, and automatically sends the network configuration informationto the terminal within the preset distance range, which simplifies auser's operation process. On this basis, the following problem may occurin specific implementation.

For example, if a real terminal S1 intends to access a home WiFinetwork, where the real terminal S1 may be a certain indoor notebookcomputer, according to the solution in the embodiment of the presentinvention, under normal circumstances, a user only needs to make theterminal S1 close to an AP mate, and the AP mate executes the foregoingprocess of determining a distance of the terminal S1. However, there maybe a fake terminal S2, and the fake terminal S2 is located outdoors andis not eligible to access the home WiFi network; in addition, theterminal S2 is a little far away from the AP mate because the terminalS2 is located outdoors, and the terminal S2 is generally beyond a presetdistance range (e.g., a preset distance of WiFi is small, for example, 1m). The fake terminal S2 may take a certain measure to enable the APmate to make wrong determination that a distance between the faketerminal S2 and the AP mate is also within the preset distance range, sothat the AP mate also sends network configuration information to thefake terminal S2. In this way, the fake terminal 2 accesses the homeWiFi. For example, the fake terminal S2 captures probe information sentby the AP mate to the terminal S1, guesses how many path losses thereare to make a distance calculated by the AP mate to be within the presetdistance range, and returns an erroneous receive power to the AP mate.For example, an actual receive power of the fake terminal S2 is 5 dB;however, to enable the AP mate to make wrong determination, the faketerminal S2 returns a receive power of 8 dB to the AP mate. In this way,a path loss calculated by the AP mate is smaller than an actual loss, sothat the AP mate may determine that the fake terminal S2 is also withinthe preset distance range, causing that the fake terminal S2 accessesthe network successfully.

To avoid the foregoing case of the fake terminal, the followingEmbodiment 5 to Embodiment 7 describe several feasible solutions foridentifying a real terminal and a fake terminal to better ensuresecurity of setting up a WiFi network connection.

Embodiment 5

FIG. 5 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention. In this embodiment, a message is transmitted twice,that is, the message is transmitted from an AP mate to a terminal, andthe message is transmitted from the terminal to the AP mate; adifference between path losses of the two transmissions is compared; adetermination basis is that a difference between path losses caused intwo transmissions is usually large because a fake terminal adopts amanner of guessing a loss; the AP mate has high sensitivity, and obtainsthe difference between the two losses; a difference between two pathlosses caused by a real device is generally small and the two pathlosses are basically the same.

This embodiment is a process that integrates identifying authenticity ofa terminal with determining a distance of the terminal. Therefore, thisembodiment is equivalent to a combination of Embodiment 3 and Embodiment4. However, a sequence of the foregoing two transmissions is notlimited. In this embodiment, that transmission from the AP mate to theterminal is executed first and then transmission from the terminal tothe AP mate is executed is taken as an example for description. As shownin FIG. 5, the method may include:

501. The AP mate and the terminal obtain a key by using a key exchangealgorithm.

502. The AP mate sends a probe message to the terminal by using a firsttransmit power P.

503. The terminal returns a first response message to the AP mate, wherethe first response message carries a first receive power PA when theterminal receives the probe message.

504. The AP mate calculates, according to the first transmit power P andthe first receive power PA for transmission of the probe message, afirst path loss when the probe message is transmitted from the AP mateto the terminal.

The first path loss is P-PA.

505. The AP mate determines, according to the first path loss, whether adistance between the terminal and the AP mate is within a presetdistance range.

If a determination result of the AP mate is that the terminal is withinthe preset distance range, then, to ensure that the terminal is a realterminal, continue to execute 506; otherwise, if a determination resultof the AP mate is that the terminal is not within the preset distancerange, the process ends.

506. The AP mate sends a probe message to the terminal, where the probemessage is used to instruct the terminal to send a second responsemessage by using a second transmit power P1.

507. The terminal sends the second response message to the AP mate byusing the second transmit power P1.

508. The AP mate obtains a second receive power P1A when the AP matereceives the second response message.

509. The AP mate calculates, according to the obtained second transmitpower and second receive power P1A, a path loss when the probe messageis transmitted from the terminal to the AP mate.

A second path loss is P1-P1A.

510. The AP mate determines, according to the second path loss, whethera distance between the terminal and the AP mate is within the presetdistance range.

If a determination result of the AP mate is that the terminal is withinthe preset distance range, continue to execute 511; otherwise, theprocess ends.

511. Compare the second path loss with the first path loss, anddetermine whether a loss variation value between the two is within apreset loss variation value range.

If the terminal is a real terminal, namely, a real device, a differencebetween path losses in the two transmissions is not large, and even ifthere is a slight difference, the slight difference is a minordifference within a reasonable range. However, if the terminal is a faketerminal, because the fake terminal guesses a path loss, and what thefake terminal reports to the AP mate is not a real receive power, adifference between path losses in the two transmissions is large. It isvery difficult for the fake terminal to guess the path loss correctly,and the AP mate has high sensitivity. Therefore, the AP mate cangenerally discover the large difference between the path losses in thetwo transmissions performed by the fake terminal.

The loss variation value may be a difference, or a ratio, or anothermathematical value, which can indicate variation, between the first pathloss and the second path loss. In this embodiment, the AP mate may set apreset loss variation value range, where the preset loss variation valuerange is set by taking a fact that a reasonable tiny difference may alsoexist between the two transmissions performed by the real terminal intoconsideration. The AP mate may determine whether the difference betweenthe second path loss and the first path loss is within the preset lossrange; if yes, it indicates that the terminal is a real device, and 512continues to be executed; otherwise, it indicates that the terminal is afake terminal, and the process ends. Then, the AP mate does not sendnetwork configuration information to the terminal, thereby avoidingaccess of the fake terminal and improving security of network setup.

512. The AP mate sends network configuration information to theterminal.

513. The terminal sets up a network connection with the AP according tothe network configuration information.

Embodiment 6

FIG. 6 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention. In this embodiment, authenticity of a terminal isidentified according to the fluctuation of path losses, specifically,according to the variance of multiple path losses. Assuming that a faketerminal is set outdoors, where an outdoor environment is complex, andwhen the fake terminal communicates with an indoor AP mate, a signalneeds to go through obstacles such as walls. Therefore, the fluctuationof path losses in multiple times of message interaction is large. Evenif the fake terminal is not set outdoors, no matter where the faketerminal is located, because the fake terminal does not report a powerto the AP mate truthfully (if the fake terminal reports a powertruthfully, the AP mate easily identifies a real distance of the faketerminal), the fluctuation of path losses in multiple times of messageinteraction is still large. Generally, the fake terminal does not guessa path loss very accurately.

This embodiment is also a process that integrates identifying theauthenticity of a terminal with determining a distance of the terminal.Therefore, determining a path loss variance is combined with determiningthe distance of the terminal. However, a sequence of executing these twoaspects is not limited. For example, the authenticity of the terminalmay be determined first by using the path loss variance, and if theterminal is a real terminal, the distance of the terminal is determined;or, as described in Embodiment 5, the distance of the terminal isdetermined first, and if the distance meets a condition, theauthenticity of the terminal is determined; or, the authenticity of theterminal and the distance of the terminal are determined together. Thisembodiment takes the former as an example, that is, determining theauthenticity of the terminal is executed first. As shown in FIG. 6, themethod may include:

601. The AP mate and the terminal obtain a key by using a key exchangealgorithm.

602. The AP mate and the terminal perform multiple times of messageinteraction.

The multiple times of message interaction refer to executing multipleunidirectional message transmissions between the AP mate and theterminal. For example, for the first time, the AP mate sends a probemessage to the terminal by using a certain transmit power; for thesecond time, the AP mate instructs the terminal to send a responsemessage by using a certain transmit power; for the third time, the APmate sends the probe message to the terminal by using a certain transmitpower.

603. The AP mate calculates a floating variation value of path losses inmultiple times of message interaction, for example, a variance.

The AP mate obtains a transmit power and a receive power in eachunidirectional message transmission. For an obtaining manner, referencemay be made to the foregoing embodiments; then, the AP mate calculates apath loss in each unidirectional transmission according to the transmitpower and the receive power, and may obtain multiple path loss values intotal; finally, the AP mate calculates the floating variation value ofthe multiple path losses.

The floating variation value may be a variance, or a standard deviation,or another mathematical value, which can indicate the variation, of themultiple path losses.

604. The AP mate determines whether the obtained floating variationvalue is within a preset floating variation value range, for example, apreset variance range.

Considering that generally a reasonable fluctuation is unavoidable inmultiple message transmissions, a preset floating variation value rangemay be set in the AP mate. So long as the variance obtained in 603 iswithin the preset floating variation value range, it indicates that theterminal is a real device, and 605 continues to be executed; otherwise,it indicates that a fluctuation in the multiple message transmissions islarge and exceeds a reasonable range, the terminal is a fake terminal,and the process ends.

605. The AP mate sends a probe message to the terminal by using atransmit power P.

606. The terminal reports, to the AP mate, a receive power PA whenreceiving the probe message.

607. The AP mate calculates, according to the transmit power P and thereceive power PA for transmission of the probe message, a path loss whenthe probe message is transmitted from the AP mate to the terminal.

The path loss is P-PA.

608. The AP mate determines, according to the path loss, whether adistance between the terminal and the AP mate is within a presetdistance range.

If a determination result of the AP mate is that the terminal is withinthe preset distance range, continue to execute 609; otherwise, theprocess ends.

609. The AP mate sends network configuration information to theterminal.

610. The terminal sets up a network connection with the AP according tothe network configuration information.

Embodiment 7

FIG. 7 is a schematic signaling diagram of still another embodiment of amethod for setting up a wireless network connection according to thepresent invention. In this embodiment, an example that a distance of aterminal is determined first and then authenticity of the terminal isdetermined according to a path loss variance is taken. As shown in FIG.7, the method includes:

701. An AP mate and a terminal obtain a key by using a key exchangealgorithm.

702. The AP mate sends a probe message to the terminal by using atransmit power P.

703. The terminal reports, to the AP mate, a receive power PA whenreceiving the probe message.

704. The AP mate calculates, according to the transmit power P and thereceive power PA for transmission of the probe message, a path loss P-PAwhen the probe message is transmitted from the AP mate to the terminal.

705. The AP mate determines, according to the path loss, whether adistance between the terminal and the AP mate is within a presetdistance range.

If a determination result of the AP mate is that the terminal is withinthe preset distance range, continue to execute 706 to determineauthenticity of the terminal; otherwise, the process ends.

706. The AP mate and the terminal perform multiple times of messageinteraction.

707. The AP mate calculates a variance of path losses in the multipletimes of probe message interaction.

708. The AP mate determines whether the obtained variance is within apreset variance range.

If the variance obtained in 707 is within the preset variance range, itindicates that the terminal is a real device, and 709 continues to beexecuted; otherwise, it indicates that the fluctuation in multiplemessage transmissions is large and exceeds a reasonable range, theterminal is a fake terminal, and the process ends.

709. The AP mate sends network configuration information to theterminal.

710. The terminal sets up a network connection with the AP mateaccording to the network configuration information.

The foregoing several examples list several feasible solutions; however,in specific implementation, the present invention is not limitedthereto, and changes may be made to multiple solutions. For example,determining the path loss variance may also be combined with the mannerin which the AP mate instructs the terminal to send a response messageby using a certain transmit power, and an execution sequence is notlimited; or, determining the path loss variance and identifying theauthenticity of the terminal through two message transmissions are bothadopted, to further ensure accuracy of identifying a fake terminal. Forexample, FIG. 8 is a schematic signaling diagram of still anotherembodiment of a method for setting up a wireless network connectionaccording to the present invention. FIG. 8 shows an optional manner thatincludes determining authenticity of a terminal according to a path lossvariance, determining the authenticity of the terminal according to avariation value of two path losses, and determining a distance accordingto a path loss are combined. All steps in FIG. 8 are described in theforegoing embodiments, and these steps are combined together here. Thespecific solution of each step is the same as that in the foregoingembodiments, and details are not further described.

Embodiment 8

An embodiment of the present invention provides a wireless accessdevice, where the wireless access device is the AP mate in the foregoingmethod embodiments.

FIG. 9 is a schematic structural diagram of an embodiment of a firstdevice according to the present invention. As shown in FIG. 9, thewireless access device may include a message transmitting unit 81, adistance determining unit 82, and an information sending unit 83.

The message transmitting unit 81 is configured to: send a probe messageto a second device by using a first transmit power, and receive a firstresponse message returned by the second device, where the first responsemessage carries a first receive power when the second device receivesthe probe message; or, send a probe message to the second device, wherethe probe message is used to instruct the second device to send a secondresponse message by using a second transmit power, receive the secondresponse message, and obtain, through detection, a second receive powerwhen receiving the second response message; or, send a probe message toa second device by using a first transmit power, where the probe messageis used to instruct the second device to send a third response messageby using a second transmit power, receive the third response message,where the third response message carries a first receive power when thesecond device receives the probe message, and obtain, through detection,a second receive power when receiving the third response message.

The distance determining unit 82 is configured to: obtain, according tothe first transmit power and the first receive power or according to thesecond transmit power and the second receive power, a path loss betweenthe first device and the second device; and determine, according to thepath loss, that a distance between the first device and the seconddevice is within a preset distance range.

The information sending unit 83 is configured to, when the distancedetermining unit determines that the distance between the first deviceand the second device is within the preset distance range, send networkconfiguration information to the second device, so that the seconddevice sets up, according to the network configuration information, aconnection with the wireless network.

FIG. 10 is a schematic structural diagram of another embodiment of afirst device according to the present invention. On the basis of thestructure shown in FIG. 9, the wireless access device may furtherinclude a device identifying unit 84.

The path loss obtained by the distance determining unit 82 according tothe first transmit power and the first receive power is a first pathloss, and the path loss obtained according to the second transmit powerand the second receive power is a second path loss.

The device identifying unit 84 is configured to: compare the second pathloss with the first path loss; if a loss variation value between the twois within a preset loss variation value range, identify a terminal as areal device, and instruct the information sending unit to send networkconfiguration information to the second device.

Further, there are multiple path losses obtained by the distancedetermining unit 82.

The device identifying unit 84 is further configured to: calculate afloating variation value of the multiple path losses, and if thefloating variation value is within a preset floating variation valuerange, identify a terminal as a real device, and instruct theinformation sending unit to send network configuration information tothe second device.

Further, the first device may further include a key exchanging unit 85configured to, before the probe message is sent to the second device,obtain a key by using a key exchange algorithm with the second device toencrypt, by using the key, the probe message sent to the second deviceand decrypt, by using the key, a response message received from thesecond device, where the response message is the first response message,the second response message or the third response message.

Embodiment 9

FIG. 11 is a schematic structural diagram of an embodiment of a seconddevice according to the present invention. The second device may executethe method in any embodiment of the present invention. As shown in FIG.11, the second device in this embodiment may include a messagetransmitting unit 1001, an information receiving unit 1002, and aconnection setup unit 1003.

The message transmitting unit 1001 is configured to: receive a probemessage that is sent by the first device by using a first transmitpower, and return a first response message to the first device, wherethe first response message carries a first receive power when the seconddevice receives the probe message; or, receive a probe message sent bythe first device, where the probe message is used to instruct the seconddevice to send a second response message by using a second transmitpower, and send the second response message to the first device, so thatthe first device obtains, through detection, a second receive power whenreceiving the second response message; or, receive a probe message thatis sent by the first device by using a first transmit power, where theprobe message is used to instruct the second device to send a thirdresponse message by using a second transmit power, send the thirdresponse message to the first device, where the third response messagecarries a first receive power when the second device receives the probemessage, so that the first device obtains, through detection, a secondreceive power when receiving the third response message.

The information receiving unit 1002 is configured to receive networkconfiguration information which is needed for accessing a wirelessnetwork and sent by the first device, where the network configurationinformation is sent by the first device when the first devicedetermines, according to the first transmit power and the first receivepower or according to the second transmit power and the second receivepower, that a distance between the first device and the second device iswithin a preset distance range.

The connection setup unit 1003 is configured to set up a connection withthe wireless network according to the network configuration information.

Further, the second device further includes a key exchanging unit 1004configured to, before the probe message sent by the first device isreceived, obtain a key by using a key exchange algorithm with the firstdevice to encrypt, by using the key, a response message sent to thefirst device and decrypt, by using the key, the probe message receivedfrom the first device, where the response message is the first responsemessage, the second response message or the third response message.

Embodiment 10

FIG. 12 is a schematic structural diagram of still another embodiment ofa first device according to the present invention. As shown in FIG. 12,the first device in this embodiment may include a memory 1101 and aprocessor 1102.

The memory 1101 is configured to store a preset distance range between asecond device and a wireless device and network configurationinformation.

The processor 1102 is configured to send a probe message to the seconddevice by using a first transmit power, and receive a first responsemessage returned by the second device, where the first response messagecarries a first receive power when the second device receives the probemessage; or, send a probe message to the second device, where the probemessage is used to instruct the second device to send a second responsemessage by using a second transmit power, receive the second responsemessage, and obtain, through detection, a second receive power whenreceiving the second response message; or, send a probe message to thesecond device by using a first transmit power, where the probe messageis used to instruct the second device to send a third response messageby using a second transmit power, receive the third response message,where the third response message carries a first receive power when thesecond device receives the probe message, and obtain, through detection,a second receive power when receiving the third response message; and,obtain, according to the first transmit power and the first receivepower or according to the second transmit power and the second receivepower, a path loss between the first device and the second device;determine, according to the path loss, that a distance between the firstdevice and the second device is within the preset distance range; andwhen the distance determining unit determines that the distance betweenthe first device and the second device is within the preset distancerange, send the network configuration information to the second device.

Further, the memory 1101 is further configured to store a preset lossvariation value range. The processor 1102 is specifically configured to:compare a second path loss with a first path loss, and if a lossvariation value between the two is within the preset loss variationvalue range, identify a terminal as a real device, and send the networkconfiguration information to the second device.

Further, the memory 1101 is configured to store a preset floatingvariation value range. The processor 1102 is further configured to:calculate a floating variation value of multiple path losses, and if thefloating variation value is within the preset floating variation valuerange, identify a terminal as a real device.

Further, the processor 1102 is configured to, before the probe messageis sent to the second device, obtain a key by using a key exchangealgorithm with the second device to encrypt, by using the key, the probemessage sent to the second device and decrypt, by using the key, aresponse message received from the second device, where the responsemessage is the first response message, the second response message orthe third response message.

FIG. 13 is a schematic structural diagram of another embodiment of asecond device according to the present invention. As shown in FIG. 13,the second device in this embodiment may include a memory 1201 and aprocessor 1202.

The memory 1201 is configured to store network configuration informationreceived from a first device.

The processor 1202 is configured to: receive a probe message that issent by the first device by using a first transmit power, and return afirst response message to the first device, where the first responsemessage carries a first receive power when the second device receivesthe probe message; or, receive a probe message sent by the first device,where the probe message is used to instruct the second device to send asecond response message by using a second transmit power, and send thesecond response message to the first device, so that the first deviceobtains, through detection, a second receive power when receiving thesecond response message; or, receive a probe message that is sent by thefirst device by using a first transmit power, where the probe message isused to instruct the second device to send a third response message byusing a second transmit power, and send the third response message tothe first device, where the third response message carries a firstreceive power when the second device receives the probe message, so thatthe first device obtains, through detection, a second receive power whenreceiving the third response message; and, receive the networkconfiguration information which is needed for accessing a wirelessnetwork and sent by the first device, where the network configurationinformation is sent by the first device when the first devicedetermines, according to the first transmit power and the first receivepower or according to the second transmit power and the second receivepower, that a distance between the first device and the second device iswithin a preset distance range; and set up a connection with thewireless network according to the network configuration information.

Further, the processor 1202 is further configured to, before the probemessage sent by the first device is received, obtain a key by using akey exchange algorithm with the first device to encrypt, by using thekey, a response message sent to the first device and decrypt, by usingthe key, the probe message received from the first device, where theresponse message is the first response message, the second responsemessage or the third response message.

Persons of ordinary skill in the art should understand that all or partof the steps of the foregoing method embodiments may be implemented by aprogram instructing relevant hardware. The program may be stored in acomputer readable storage medium. When the program is run, the steps ofthe foregoing method embodiments are performed. The storage mediumincludes any medium capable of storing program codes, such as read-onlymemory (ROM), random-access memory (RAM), magnetic disk, or opticaldisk.

Finally, it should be noted that the foregoing embodiments are merelyused for describing the technical solutions of the present invention,rather than limiting the present invention. Although the presentinvention is described in detail with reference to the foregoingembodiments, persons of ordinary skill in the art should understand thatthey may still make modifications to the technical solutions describedin the foregoing embodiments, or make equivalent substitutions to partor all of the technical features; however, these modifications orsubstitutions do not make the essence of corresponding technicalsolutions depart from the scope of the technical solutions of theembodiments of the present invention.

What is claimed is:
 1. A method for setting up a wireless networkconnection comprising: sending, by a first device, a first probe messageto a second device by using a first transmit power, and receiving afirst response message returned by the second device, wherein the firstresponse message carries a first receive power when the second devicereceives the first probe message; or sending, by the first device, asecond probe message to the second device, wherein the second probemessage is used to instruct the second device to send a second responsemessage by using a second transmit power, and receiving, by the firstdevice, the second response message, and obtaining, through detection, asecond receive power when receiving the second response message; orsending, by the first device, a third probe message to the second deviceby using the first transmit power, wherein the third probe message isused to instruct the second device to send a third response message byusing the second transmit power, receiving, by the first device, thethird response message, wherein the third response message carries thefirst receive power when the second device receives the third probemessage, and obtaining, by the first device through detection, thesecond receive power when receiving the third response message;obtaining, by the first device according to the first transmit power andthe first receiver power or according to the second transmit power andthe second receive power, a path loss between the first device and thesecond device; and sending, by the first device, network configurationinformation needed for accessing a wireless network to the second devicesuch that the second device sets up a connection with the wirelessnetwork according to the network configuration information whendetermining that a distance between the first device and the seconddevice is within a preset distance range according to the path loss. 2.The method for setting up a wireless network connection according toclaim 1, wherein the path loss obtained by the first device according tothe first transmit power and the first receive power is a first pathloss, wherein the path loss obtained by the first device according tothe second transmit power and the second receive power is a second pathloss, wherein after determining, by the first device according to thepath loss, that the distance between the first device and the seconddevice is within the preset distance range and before sending, by thefirst device, the network configuration information needed for accessingthe wireless network to the second device, the method further comprisescomparing, by the first device, the second path loss with the first pathloss, and identifying a terminal as a real device when a loss variationvalue between the first path loss and the second path loss is within apreset loss variation value range.
 3. The method for setting up awireless network connection according to claim 1, wherein multiple pathlosses are obtained by the first device, wherein after determining, bythe first device according to the path loss, that the distance betweenthe first device and the second device is within the preset distancerange and before sending, by the first device, the network configurationinformation needed for accessing the wireless network to the seconddevice, the method further comprises calculating, by the first device, afloating variation value of the multiple path losses, and identifyingthe terminal as a real device when the floating variation value iswithin a preset floating variation value range.
 4. The method forsetting up a wireless network connection according to claim 1, whereinbefore sending, by the first device, the first, the second, or the thirdprobe message to the second device, the method further comprisesobtaining, by the first device, a key by using a key exchange algorithmwith the second device to encrypt, by using the key, the first, thesecond, or the third probe message sent to the second device anddecrypt, by using the key, the first, the second, or the third responsemessage received from the second device.
 5. A method for setting up awireless network connection comprising: receiving, by a second device, afirst probe message that is sent by a first device by using a firsttransmit power, and returning a first response message to the firstdevice, wherein the first response message carries a first receive powerwhen the second device receives the first probe message; or receiving,by the second device, a second probe message sent by the first device,wherein the second probe message is used to instruct the second deviceto send a second response message by using a second transmit power, andsending, by the second device, the second response message to the firstdevice such that the first device obtains, through detection, a secondreceive power when receiving the second response message; or receiving,by the second device, a third probe message that is sent by the firstdevice by using the first transmit power, wherein the third probemessage is used to instruct the second device to send a third responsemessage by using the second transmit power, and sending, by the seconddevice, the third response message to the first device, wherein thethird response message carries the first receive power when the seconddevice receives the third probe message such that the first deviceobtains, through detection, the second receive power when receiving thethird response message; receiving, by the second device, networkconfiguration information which is needed for accessing a wirelessnetwork and sent by the first device, wherein the network configurationinformation is sent by the first device when the first devicedetermines, according to the first transmit power and the first receivepower or according to the second transmit power and the second receivepower, that a distance between the first device and the second device iswithin a preset distance range; and setting up, by the second device, aconnection with the wireless network according to the networkconfiguration information.
 6. The method for setting up a wirelessnetwork connection according to claim 5, wherein before receiving, bythe second device, the first, the second, or the third probe messagesent by the first device, the method further comprises obtaining, by thesecond device, a key by using a key exchange algorithm with the firstdevice to encrypt, by using the key, the first, the second, or the thirdresponse message sent to the first device and decrypt, by using the key,the first, the second, or the third probe message received from thefirst device.
 7. A first device comprising: a message transmitting unitconfigured to: send a first probe message to a second device by using afirst transmit power, and receive a first response message returned bythe second device, wherein the first response message carries a firstreceive power when the second device receives the first probe message;or send a second probe message to the second device, wherein the secondprobe message is used to instruct the second device to send a secondresponse message by using a second transmit power, receive the secondresponse message, and obtain, through detection, a second receive powerwhen receiving the second response message; or send a third probemessage to the second device by using the first transmit power, whereinthe third probe message is used to instruct the second device to send athird response message by using the second transmit power, receive thethird response message, wherein the third response message carries thefirst receive power when the second device receives the third probemessage, and obtain, through detection, the second receive power whenreceiving the third response message; a distance determining unitconfigured to: obtain, according to the first transmit power and thefirst receive power or according to the second transmit power and thesecond receive power, a path loss between the first device and thesecond device; and determine, according to the path loss, that adistance between the first device and the second device is within apreset distance range; and an information sending unit configured tosend network configuration information to the second device such thatthe second device sets up, according to the network configurationinformation, a connection with the wireless network when the distancedetermining unit determines that the distance between the first deviceand the second device is within the preset distance range.
 8. The firstdevice according to claim 7, wherein the path loss obtained by thedistance determining unit according to the first transmit power and thefirst receive power is a first path loss, wherein the path loss obtainedaccording to the second transmit power and the second receive power is asecond path loss, and wherein first device further comprises a deviceidentifying unit configured to compare the second path loss with thefirst path loss, and identify the terminal as a real device and instructthe information sending unit to send the network configurationinformation to the second device when a loss variation between the firstpath loss and the second path loss is within a preset loss variationvalue range.
 9. The first device according to claim 8, wherein multiplepath losses are obtained by the distance determining unit, and whereinthe device identifying unit is further configured to calculate afloating variation value of the multiple path losses, and identify theterminal as a real device and instruct the information sending unit tosend the network configuration information to the second device when thefloating variation value is within a preset floating variation valuerange.
 10. The first device according to claim 7, further comprising akey exchanging unit configured to, before the first, the second, or thethird probe message is sent to the second device, obtain a key by usinga key exchange algorithm with the second device to encrypt, by using thekey, the first, the second, or the third probe message sent to thesecond device and decrypt, by using the key, the first, the second, orthe third response message received from the second device.
 11. A seconddevice comprising: a message transmitting unit configured to: receive afirst probe message that is sent by the first device by using a firsttransmit power, and return a first response message to the first device,wherein the first response message carries a first receive power whenthe second device receives the first probe message; or receive a secondprobe message sent by the first device, wherein the second probe messageis used to instruct the second device to send a second response messageby using a second transmit power, and send the second response messageto the first device such that the first device obtains, throughdetection, a second receive power when receiving the second responsemessage; or receive a third probe message that is sent by the firstdevice by using the first transmit power, wherein the third probemessage is used to instruct the second device to send a third responsemessage by using the second transmit power, send the third responsemessage to the first device, wherein the third response message carriesthe first receive power when the second device receives the third probemessage such that the first device obtains, through detection, thesecond receive power when receiving the third response message; aninformation receiving unit configured to receive network configurationinformation that is needed for accessing a wireless network and sent bythe first device, wherein the network configuration information is sentby the first device when the first device determines, according to thefirst transmit power and the first receive power or according to thesecond transmit power and the second receive power, that a distancebetween the first device and the second device is within a presetdistance range; and a connection setup unit configured to set up aconnection with the wireless network according to the networkconfiguration information.
 12. The second device according to claim 11,further comprising a key exchanging unit configured to, before thefirst, the second, or the third probe message sent by the first deviceis received, obtain a key by using a key exchange algorithm with thefirst device to encrypt, by using the key, the first, the second, or thethird response message sent to the first device and decrypt, by usingthe key, the first, the second, or the third probe message received fromthe first device.